﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SnmpForm.APConfig
{
    public partial class ucApWorkingMode : ucAPConfig
    {
        public ucApWorkingMode()
        {
            InitializeComponent();
        }

        public override bool Update(bool bView = true)
        {
            DbWrapper.DbDataTypes.WirelessInfo info = m_ap.GetApWireless();
            if (bView)
            {
                if (info.workmode == "enable")
                {
                    radioButtonAp.Checked = true;
                }
                else if (info.workmode == "disable")
                {
                    radioButtonRoute.Checked = true;
                }
            }
            else
            {
                if (radioButtonAp.Checked)
                {
                    info.workmode = "enable";
                }
                else if (radioButtonRoute.Checked)
                {
                    info.workmode = "disable";
                }
                else
                {
                }
            }
            return true;
        }

        public override bool SyncToApCommit()
        {
            DbWrapper.DbDataTypes.WirelessInfo infoWireless =
               m_ap.GetApWireless();
            bool bSuccess = m_ap.SetApWorkMode(infoWireless.workmode);
            return bSuccess;
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            Update(false);
            if (SyncToAp())
            {
                if (SaveToDb())
                {
                    NoticeConfigFormClose();
                }
            }
        }

        public override void LoadAp()
        {
            Update();
            //
            bool bPrivilege = BusinessWrapper.User.Instance.Permision(
                BusinessWrapper.Types.Privilege.ManageAP.ApWorkingMode.Save.permision);
            buttonSave.Visible = bPrivilege;
        }
    }
}
